# 导入模型包
from django.db import models


# 创建到用户数据表
class Users(models.Model):
    id = models.AutoField(primary_key=True)
    username = models.CharField(max_length=255, verbose_name='用户名')
    passwd = models.CharField(max_length=255, verbose_name='用户密码')
    datetime = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = "users"  # 数据表名


# 商品模型
class Goods(models.Model):
    gid = models.AutoField(primary_key=True)
    name = models.CharField(max_length=200, verbose_name="商品名称")
    img = models.CharField(max_length=200, verbose_name="商品图片")
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="商品价格")
    count = models.CharField(max_length=200, verbose_name="商品数量")

    class Meta:
        db_table = "goods"  # 商品表


# 用户购物车
class goodsCars(models.Model):

    cid = models.AutoField(primary_key=True, verbose_name="购物车id")
    # gid = models.IntegerField(verbose_name="商品id")
    good = models.ForeignKey('Goods', on_delete=models.CASCADE)
    chice_count = models.IntegerField(verbose_name="用户选择数量")
    uid = models.IntegerField(verbose_name="添加购物车用户id")

    class Meta:
        db_table = "goodscars"  # 设置数据库表名

